/*
 * @ProjectName: 编程学习
 * @Copyright:   2019 HangZhou Ashe Dev, Ltd. All Right Reserved.
 * @address:     https://yiyuery.github.io/NoteBooks/
 * @date:        2020/2/24 10:37 下午
 * @description: 本内容仅限于编程技术学习使用，转发请注明出处.
 */
package com.yi.yier.boot.autoconfigure.codegenerator.gen.model.impl;

import com.yi.yier.boot.autoconfigure.codegenerator.gen.AbstractCodeGenerator;
import com.yi.yier.boot.autoconfigure.codegenerator.gen.ICodeGenerator;
import com.yi.yier.boot.autoconfigure.codegenerator.gen.extend.ITemplateContextBuilder;
import com.yi.yier.boot.autoconfigure.codegenerator.common.GenCodeParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *
 * </p>
 *
 * @author Yiyuery
 * @version V1.0.0
 * @date 2020/2/24 10:37 下午
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人}  2020/2/24
 * @modify reason: {方法名}:{原因}
 * ...
 */
@Slf4j
public class CodeGeneratorAssistant extends AbstractCodeGenerator implements ICodeGenerator {

    private static final List<ICodeGenerator> codeGeneratorList = new ArrayList<>();

    @Override
    public void genCode(GenCodeParam genCodeParam) {
        Assert.isTrue(CollectionUtils.isNotEmpty(codeGeneratorList),"未注入 ICodeGenerator 实现类");
        Assert.isTrue(Objects.nonNull(templateContextBuilder),"未注入 ITemplateContextBuilder");

        codeGeneratorList.forEach(p->{
            p.registerContextBuilder(templateContextBuilder);
            p.genCode(genCodeParam);
        });
    }

    public CodeGeneratorAssistant addGenerator(ICodeGenerator codeGenerator) {
        codeGeneratorList.add(codeGenerator);
        return this;
    }
}
